/*
 * Copyright (c) 2019 Wormpex.com. All Rights Reserved.
 */

package com.sk.volat;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 指令重排 智能根据语义解释，很难验证
 *
 * @author ke.su date: 2019-11-13 Time: 上午10:40
 */
public class VolatileTest3 {

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newScheduledThreadPool(2);

        A1 a = new A1();

        executorService.execute(() -> {
            a.one();
        });
        executorService.execute(() -> {
            a.two();
        });
    }
}

class A1 {

    public int num = 1;
    public boolean res = true;

    public volatile int a = 1;

    public void one() {
        num = 10;

        // for (int i = 1; i < 1000000000; i++) {
        //     a = i;
        // }

        num = 3;
        res = false;

    }

    public void two() {
        if (res) {
            System.out.println(num);
        }else{
            System.out.println(num);
        }
    }


}